package com.hngy.scala

import org.apache.spark.{SparkConf, SparkContext}

object BroadcastOpScala {
  def main(args: Array[String]): Unit = {
    var conf = new SparkConf()
    conf.setAppName("BroadcastOpScala")
      .setMaster("local")
    val sc = new SparkContext(conf)

    val dataRDD = sc.parallelize(Array(1,2,3,4,5))
    val varable = 2

    //定义广播变量
    val varableBroadcast = sc.broadcast(varable)
    //使用广播变量,调用其value方法
    dataRDD.map(_ * varableBroadcast.value).foreach(println(_))

    sc.stop()
  }
}
